/*
 * myaffine.h
 *
 *  Created on: Jul 22, 2012
 *      Author: Nautilus
 */

#ifndef MYAFFINE_H_
#define MYAFFINE_H_

#include "base.h"

typedef struct tagDoubleMatrix
{
	int nRow;
	int nCol;
	double *m;
} MATRIX;

// Perspective projection transformation matrix
double PPMatrix[4][4]={
		{1,  0,  0, 0},
		{0,  1,  0, 0},
		{0,  0,  1, 0},
		{0,  0,  1, 0}};


void initMatrix(MATRIX *);
void releaseMatrix(MATRIX *);

/*
 *  Calculate R = A * B
 * */
unsigned char multiply(double *A[], int rowA, int colA, double *B[], int rowB, int colB, double *R[]);
unsigned char multiplyM(MATRIX, MATRIX, MATRIX *);

/*
 * 	This calculates transpose matrix of A
 */
unsigned char T(double *A[], int rowA, int colA, double *T[]);

/* make affine transformation */
unsigned char affineTransform(double m[4][4], double *p, double *R);
unsigned char affineTransformM(MATRIX , double P[], double R[]);

void translate(double tx, double ty, double tz, double *[]);
void translateM(double tx, double ty, double tz, MATRIX m);

void rotateX(double theta, double m[][4]);
void rotateY(double theta, double m[][4]);
void rotateZ(double theta, double m[][4]);
void rotate(double theta, POINT3D v, double m[][4]);
void rotate_1(double theta, double v[], double m[][4]);
void rotate_2(double theta, double vx, double vy, double yz, double m[][4]);
void rotateAboutArbitaryAxis(double theta, POINT3D A, POINT3D B, double m[][4]);

unsigned char scale(double sx, double sy, double sz, double *[]);
unsigned char shear(double xy, double yx, double xz, double zx, double yz, double zy, double *[]);
void reflectX(double *[]);
void reflectXM(MATRIX );
void reflectY(double *[]);
void reflectYM(MATRIX );
void reflectZ(double *[]);
void reflectZM(MATRIX );

#endif /* MYAFFINE_H_ */
